package org.dromara.pdf.pdfbox.convertor;

import org.dromara.pdf.pdfbox.base.BaseTest;
import org.dromara.pdf.pdfbox.core.base.Document;
import org.dromara.pdf.pdfbox.core.ext.convertor.image.ImageConvertor;
import org.dromara.pdf.pdfbox.handler.PdfHandler;
import org.junit.Test;

import java.io.File;

/**
 * @author xsx
 * @date 2025/6/18
 * @since 1.8
 * <p>
 * Copyright (c) 2020-2024 xsx All Rights Reserved.
 * x-easypdf-pdfbox is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 * http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * </p>
 */
public class ImageConvertorTest extends BaseTest {

    /**
     * 图片转pdf测试
     */
    @Test
    public void toPdfTest() {
        for (int k = 0; k < 1; k++) {
            this.test(() -> {
                File[] files = new File("E:\\PDF\\pdfbox\\convertor\\image\\jpeg").listFiles();
                ImageConvertor convertor = PdfHandler.getDocumentConvertor().getImageConvertor();
                convertor.toPdf(files);
                Document document = convertor.flush();
                document.saveAndClose("E:\\PDF\\pdfbox\\convertor\\image\\x-easypdf1.pdf");
                System.out.println("内存占用：" + Runtime.getRuntime().totalMemory() / 1024 / 1024);
            });

            this.test(() -> {
                File[] files = new File("E:\\PDF\\pdfbox\\convertor\\image\\png").listFiles();
                ImageConvertor convertor = PdfHandler.getDocumentConvertor().getImageConvertor();
                convertor.toPdf(files);
                Document document = convertor.flush();
                document.saveAndClose("E:\\PDF\\pdfbox\\convertor\\image\\x-easypdf2.pdf");
                System.out.println("内存占用：" + Runtime.getRuntime().totalMemory() / 1024 / 1024);
            });
        }
    }
}
